﻿using AutoMapper;
using MediatR;
using SmartCity.ProcessEngine.API.Write.Application.Commands.FormType;
using SmartCity.ProcessEngine.Domain;
using SmartCity.ProcessEngine.Errorcode;
using SmartCity.ProcessEngine.Infrastructure.Interfaces;

namespace SmartCity.ProcessEngine.API.Write.Application.CommandHandlers.FormType
{
    public class FormTypeUpdateCommandHandler : IRequestHandler<FormTypeUpdateCommand, ApiResult<int>>
    {
        private readonly IBaseRepository<WF_FromType> formTypeRep;
        private readonly IMapper mapper;

        public FormTypeUpdateCommandHandler(IBaseRepository<WF_FromType> formTypeRep, IMapper mapper)
        {
            this.formTypeRep = formTypeRep;
            this.mapper = mapper;
        }

        /// <summary>
        /// 处理
        /// </summary>
        /// <param name="request">请求</param>
        /// <param name="cancellationToken">取消</param>
        /// <returns>返回删除结果任务</returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<ApiResult<int>> Handle(FormTypeUpdateCommand request, CancellationToken cancellationToken)
        {
            ApiResult<int> result = new ApiResult<int>();
            result.code = ApiEnum.UpdateSuccess;
            result.message = "修改成功";

            WF_FromType entity = mapper.Map<WF_FromType>(request);
            await formTypeRep.UpdateAsync(entity);

            return await Task.FromResult(result);
        }
    }
}
